$(document).ready(function(){
	 if(jQuery('#currency').length){
            jQuery('#currency').change(function(){
                location.reload()
                jQuery('#formCurrency').submit();
            });
        } 
        if(jQuery('#modify_date').length){
            jQuery('#modify_date').click(function(){
                window.location.href = 'search.html';
            });
        }
		
		if(typeof(countRoom) !== 'undefined'){
			for(var i =0;i<countRoom;i++){
				  var mySwiper = new Swiper('#room-slide' + i,{
					//pagination: '.pagination',
					loop:false,
					grabCursor: true,
					paginationClickable: true
				  })
				  $('.arrow-left').on('click', function(e){
					e.preventDefault()
					mySwiper.swipePrev()
				  })
				  $('.arrow-right').on('click', function(e){
					e.preventDefault()
					mySwiper.swipeNext()
				  });
			}
		}
		  
	 if(jQuery('.slide').length){
		   var mySwiper = new Swiper('.slide',{
		//pagination: '.pagination',
		loop:false,
		grabCursor: true,
		paginationClickable: true
	  })
	}
    if($("#search").length){
        $("#search").click(function(){
            if($('#checkin').length && $('#checkin').val() === ''){
                alert('Please select check-in date');
                $('#checkin').focus();
                return false;
            }else if($('#checkout').length && $('#checkout').val() === ''){
                alert('Please select check-out date');
                $('#checkout').focus();
                return false;
            }
            else if($('#adult').length && $('#adult').val() === ''){
                alert('Please select adult');
                $('#adult').focus();
                return false;
            }/*
            else if($("#children").length && $("#children").val() === ''){
                alert('Please select children');
                $('#children').focus();
                return false;
            }
			else if($("#children").length && $("#children").val() !== '' && $("#extra").length && $("#extra").val() == ''){
                alert("Please select extrabed");
                $("#extra").focus();
                return false;
            }*/
        });
    }
    if($("#children").length){
        $("#children").change(function(){
            if($('#extrabed').length && $('#children').val() >0){
                $html = '';
                $html += 'Extra bed <select name="extrabed" id="extra">';
                $html += '<option value="">Choose Extrabed</option>';
                $html += '<option value="0">0</option>';
                for(var i=1;i<=$("#children").val();i++){
                        
                    $html += '<option value="'+i+'">' + i + '</option>';
                } 
                $('#extrabed').html($html);
            }else{
                $('#extrabed').html('');
            }
        });
    }
    if($("#checkin").length){
		$("#checkin").datepicker(
		{
			dateFormat : 'D, M dd, yy',
			altField            : "#check-in-date",
			altFormat           : "dd-mm-yy",
			showOtherMonths     : false,
			selectOtherMonths : true,
			showWeek            : false,
			changeYear          : false,
			changeMonth         : false,
			showButton: true,
			minDate: 'today',
			dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturaday'],
			sliderAccessArgs: {
				touchonly: false
			},
			onClose: function(dateText, inst){ 
				$(this).attr("disabled", false);
			},
			onSelect:function(i){
				var date2 = $('#checkin').datepicker('getDate');
				date2.setDate(date2.getDate()+1);
				$('#checkout').datepicker('setDate', date2);
				$("#checkout").datepicker("option", "minDate", date2);
			},
			beforeShow: function(input, inst) {
				$('#ui-datepicker-div').removeClass(function() {
					return $('#checkin').get(0).id; 
				});
				$('#ui-datepicker-div').addClass(this.id);            
			}
		}).on('focus',function(){
			$(this).trigger('blur');
		});
	}
	if($("#checkout" ).length){
		$("#checkout" ).datepicker({
			dateFormat : 'D, M dd, yy',
			altField            : "#check-out-date",
			altFormat           : "dd-mm-yy",
			showOtherMonths     : false,
			selectOtherMonths : true,
			showWeek            : false,
			changeYear          : false,
			changeMonth         : false,
			minDate: 'today',
			dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturaday'],
			beforeShow: function(input, inst) {
				$('#ui-datepicker-div').removeClass(function() {
					return $('#checkout').get(0).id; 
				});
				$('#ui-datepicker-div').addClass(this.id);
				setTimeout(function () {
					inst.dpDiv.css({
						left: 420.5
					});
				}, 0);
			},
			onSelect:function(i){
				
			}
		}).on('focus',function(){
			$(this).trigger('blur');
		});
	}
});